package com.xyzwps.server.paimon.app.dto

import com.xyzwps.server.paimon.Regexps
import com.xyzwps.server.paimon.ext.validOrThrow
import com.xyzwps.server.paimon.model.entity.PhoneVcode
import com.xyzwps.server.paimon.value.Phone
import io.konform.validation.Validation
import io.konform.validation.constraints.maxLength
import io.konform.validation.constraints.minLength
import io.konform.validation.constraints.pattern

data class LoginInput(
    val phone: Phone,
    val vcode: String,
    val dkey: String
) : ValidInput {
    companion object {
        val validator = Validation {
            LoginInput::phone {
//                pattern(Regexps.PHONE) TODO: 检查
            }

            LoginInput::vcode {
                pattern(Regexps.VCODE)
            }

            LoginInput::dkey {
                minLength(PhoneVcode.DKEY_MIN_LENGTH)
                maxLength(PhoneVcode.DKEY_MAX_LENGTH)
            }
        }
    }

    override fun validateOrThrow() = validator.validOrThrow(this)
}
